import time

from flask_apscheduler import APScheduler

import app
from prompting.commemor import commemoration_day


# 定时任务
def mail_send_task():
    day = commemoration_day()
    b = False
    count = 0
    if int(day) % 100 == 0:
        b = True
    else:
        for d in day:
            if day[0] != d:
                count += 1
        if count == 0:
            b = True

    if b:
        recipients = ['1585802793@qq.com', '970780868@qq.com']
        message = '亲今天是:' + time.strftime("%Y-%m-%d",
                                          time.localtime()) + '我们在一起第:' + day + '天!'
        app.send_mail('纪念日提醒', recipients, message)


def task(app_start):
    scheduler = APScheduler()
    scheduler.init_app(app_start)
    scheduler.add_job(func=mail_send_task, trigger='cron', day='*', hour='09', minute='30',
                      id='mail_send_task')
    scheduler.start()